//
//  NewsRow.swift
//  newsApp
//
//  Created by Doo Psyist on 2020/5/12.
//  Copyright © 2020 Doo Psyist. All rights reserved.
//

import SwiftUI
import UIKit

struct NewsRow: View{
    @State var showAlert = false
    var newsListItem: NewsListItem
    
    @State var isLikedinMain:Bool = false
    var body: some View {
        
        VStack(alignment: .leading) {
            
            HStack {
                Image(systemName:"book")
                    .foregroundColor(.blue)
                .shadow(radius: 1)
                .imageScale(.large)
                Text(newsListItem.title)
                    .font(.system(size:30,design:.rounded))
                    .foregroundColor(Color.red)
                    
                .bold()
                .shadow(radius: 1)
                Spacer()
                Image(systemName:self.isLikedinMain == true ? "heart.fill" : "")
                    .foregroundColor(.blue)
                .shadow(radius: 1)
                .imageScale(.large)
                    
                
            }
            
            HStack {
                Text(newsListItem.summary)
                    .font(.subheadline)
                Spacer()
                Text(newsListItem.date)
                    .font(.subheadline)
            }
            
        }.onAppear(){
            self.isLikedinMain = findNewsbyId(self.newsListItem.id)[0].like
        }
        .padding()
    }
    func collect() -> Bool {
        return true
    }
}

struct NewsRow_Previews: PreviewProvider {
    static var previews: some View {
        NewsRow(newsListItem: newsList[0])
    }
}
